package com.ruoyi.system.service.impl;

import com.ruoyi.common.annotation.DataScope;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.UserCollection;
import com.ruoyi.system.domain.vo.UserBookCollectionVo;
import com.ruoyi.system.mapper.UserCollectionMapper;
import com.ruoyi.system.service.IUserCollectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author ruoyi
 * @date 2022-12-08
 */
@Service
public class UserCollectionServiceImpl implements IUserCollectionService {
    @Autowired
    private UserCollectionMapper userCollectionMapper;

    /**
     * 查询【请填写功能名称】
     *
     * @param id 【请填写功能名称】主键
     * @return 【请填写功能名称】
     */
    @Override
    public UserCollection selectUserCollectionById(Long id) {
        return userCollectionMapper.selectUserCollectionById(id);
    }

    /**
     * 查询【请填写功能名称】列表
     *
     * @param userCollection 【请填写功能名称】
     * @return 【请填写功能名称】
     */
    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<UserCollection> selectUserCollectionList(UserCollection userCollection) {
        return userCollectionMapper.selectUserCollectionList(userCollection);
    }

    /**
     * 新增【请填写功能名称】
     *
     * @param userCollection 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int insertUserCollection(UserCollection userCollection) {
        userCollection.setCreateTime(DateUtils.getNowDate());
        return userCollectionMapper.insertUserCollection(userCollection);
    }

    /**
     * 修改【请填写功能名称】
     *
     * @param userCollection 【请填写功能名称】
     * @return 结果
     */
    @Override
    public int updateUserCollection(UserCollection userCollection) {
        return userCollectionMapper.updateUserCollection(userCollection);
    }

    /**
     * 批量删除【请填写功能名称】
     *
     * @param ids 需要删除的【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteUserCollectionByIds(String[] ids) {
        return userCollectionMapper.deleteUserCollectionByIds(ids);
    }

    /**
     * 删除【请填写功能名称】信息
     *
     * @param id 【请填写功能名称】主键
     * @return 结果
     */
    @Override
    public int deleteUserCollectionById(Long id) {
        return userCollectionMapper.deleteUserCollectionById(id);
    }

    @Override
    public boolean selectUserCollectionBySnoAndBookId(String sno, Long bookId) {
        if (userCollectionMapper.selectUserCollectionBySnoAndBookId(sno, bookId) > 0) {
            return true;
        } else {
            return false;
        }
    }

    @Override
    public int cancelCollect(@NotNull String sno, @NotNull String bookId) {
        return userCollectionMapper.cancelCollect(sno, bookId);
    }

    @Override
    @DataScope(deptAlias = "d", userAlias = "u")
    public List<UserBookCollectionVo> selectUserBookCollectionList(UserCollection userCollection) {
        return userCollectionMapper.selectUserBookCollectionList(userCollection);
    }
}
